package cn.wolfcode.mq.listener;

import cn.wolfcode.mq.MQConstant;
import cn.wolfcode.web.controller.OrderInfoController;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * 监听集群环境下本地标识库存已售完的标记删除
 * 消费消息模式：广播模式，保证每个服务都能删除
 */
@RocketMQMessageListener(
        consumerGroup = MQConstant.CANCEL_SECKILL_OVER_SIGE_CONSUMER_GROUP,
        topic = MQConstant.CANCEL_SECKILL_OVER_SIGE_TOPIC,
        messageModel = MessageModel.BROADCASTING   //将消息模式改为广播模式
)
@Component
@Slf4j
public class CancelStockOverFlagMessageListener implements RocketMQListener<String> {
    @Override
    public void onMessage(String msg) {
        log.info("[删除本地标识库存售完标记] 收到取消本地标识消息，准备删除本地标识: {}", msg);
        Long seckillId = Long.valueOf(msg);
        //删除本地标识已经售完标记
        OrderInfoController.removeStockOverFlagKey(seckillId);
    }
}
